package com.clickfarm.project.cf.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.clickfarm.framework.aspectj.lang.annotation.Log;
import com.clickfarm.framework.aspectj.lang.enums.BusinessType;
import com.clickfarm.project.cf.domain.CfNotice;
import com.clickfarm.project.cf.service.ICfNoticeService;
import com.clickfarm.framework.web.controller.BaseController;
import com.clickfarm.framework.web.domain.AjaxResult;
import com.clickfarm.common.utils.poi.ExcelUtil;
import com.clickfarm.framework.web.page.TableDataInfo;

/**
 * 公告Controller
 * 
 * @author clickfarm
 * @date 2020-06-10
 */
@RestController
@RequestMapping("/cf/notice")
public class CfNoticeController extends BaseController
{
    @Autowired
    private ICfNoticeService cfNoticeService;

    /**
     * 查询公告列表
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CfNotice cfNotice)
    {
        startPage();
        List<CfNotice> list = cfNoticeService.selectCfNoticeList(cfNotice);
        return getDataTable(list);
    }

    /**
     * 导出公告列表
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:export')")
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CfNotice cfNotice)
    {
        List<CfNotice> list = cfNoticeService.selectCfNoticeList(cfNotice);
        ExcelUtil<CfNotice> util = new ExcelUtil<CfNotice>(CfNotice.class);
        return util.exportExcel(list, "notice");
    }

    /**
     * 获取公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cfNoticeService.selectCfNoticeById(id));
    }

    /**
     * 新增公告
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:add')")
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CfNotice cfNotice)
    {
        return toAjax(cfNoticeService.insertCfNotice(cfNotice));
    }

    /**
     * 修改公告
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:edit')")
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CfNotice cfNotice)
    {
        return toAjax(cfNoticeService.updateCfNotice(cfNotice));
    }

    /**
     * 删除公告
     */
    @PreAuthorize("@ss.hasPermi('cf:notice:remove')")
    @Log(title = "公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cfNoticeService.deleteCfNoticeByIds(ids));
    }
}
